package com.augurit.gzcgwsp.readAndParseXML;


import java.io.File;
import java.net.InetAddress;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.TimerTask;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import com.augurit.common.syslog.tool.SysTraceLogWriter;
import com.augurit.gzcgwsp.readAndParseXML.service.ICsdlwjService;
import com.augurit.gzcgwsp.readAndParseXML.service.ICzzBghzService;
import com.augurit.gzcgwsp.readAndParseXML.service.ICzzNsxzService;
import com.augurit.gzcgwsp.readAndParseXML.service.ICzzShhzService;
import com.augurit.gzcgwsp.readAndParseXML.service.ICzzXzfzService;
import com.augurit.gzcgwsp.readAndParseXML.service.ICzzYsbbService;
import com.augurit.gzcgwsp.readAndParseXML.service.IDlzyService;
import com.augurit.gzcgwsp.readAndParseXML.service.IGgcsService;
import com.augurit.gzcgwsp.readAndParseXML.service.IHwCsshljCzService;
import com.augurit.gzcgwsp.readAndParseXML.service.IHwShljYsService;
import com.augurit.gzcgwsp.readAndParseXML.service.IHwShljqsService;
import com.augurit.gzcgwsp.readAndParseXML.service.IHwggService;
import com.augurit.gzcgwsp.readAndParseXML.service.IPfXzService;
import com.augurit.gzcgwsp.readAndParseXML.service.IQyzzService;
import com.augurit.gzcgwsp.readAndParseXML.service.IRqqyjyxkGdService;
import com.augurit.gzcgwsp.readAndParseXML.service.IRqqyjyxkPzService;
import com.augurit.gzcgwsp.readAndParseXML.service.ISsgdServiceImpl;
import com.augurit.gzcgwsp.readAndParseXML.service.IXnXzService;
import com.augurit.gzcgwsp.sendNotice.service.ICallWebServiceImpl;
import com.augurit.gzcgwsp.sendNotice.service.IYwClosecaseService;
import com.augurit.gzcgwsp.sendNotice.service.IYwWebserviceForWbService;
import com.augurit.gzcgwsp.sendNotice.service.IYwZhengwuInfoService;


public class ReadAndParseXMLDemo extends TimerTask {
	private static final Logger logger = Logger.getLogger(ReadAndParseXMLDemo.class);
	
	
	@Autowired
	private ISsgdServiceImpl ssgdServiceImpl;
	
	@Autowired
	private IHwggService hwggService;
	
	@Autowired
	private IQyzzService qyzzService;
	
	@Autowired
	private IRqqyjyxkGdService rqqyjyxkGdService;
	
	@Autowired
	private IRqqyjyxkPzService rqqyjyxkPzService;
	
	@Autowired
	private ICallWebServiceImpl callWebService;
	
	@Autowired
	private IYwZhengwuInfoService ywZhengwuInfoService;
	
	@Autowired
	private IDlzyService dlzyService;
	
	@Autowired
	private ICsdlwjService csdlwjService; 
	
	@Autowired
	private IYwClosecaseService ywClosecaseService;
	
	@Autowired
	private IHwCsshljCzService hwCsshljCzService;
	
	@Autowired
	private IHwShljqsService hwShljqsService;
	
	@Autowired
	private IHwShljYsService hwShljYsService;
	
	@Autowired
	private IGgcsService ggcsService;
	@Autowired
	private IPfXzService pfXzService;
	@Autowired
	private IXnXzService xnXzService;
	@Autowired
	private ICzzXzfzService czzXzfzService;
	@Autowired
	private ICzzNsxzService czzNsxzService;
	@Autowired
	private ICzzShhzService czzShhzService;
	@Autowired
	private ICzzBghzService czzBghzService;
	@Autowired
	private ICzzYsbbService czzYsbbService;
    @Autowired
    private IYwWebserviceForWbService ywWebserviceForWbService;
	
	@Override
	public void run() {
//		String projectPath = "/resources/AttacheFile"; 
//		InetAddress addr = null;
//		try {
//			addr = InetAddress.getLocalHost();		
//			String ip=addr.getHostAddress().toString();//获得本机IP
//			String address=addr.getHostName().toString();//获得本机名称
//			String path = getClass().getProtectionDomain().getCodeSource().getLocation().getPath();//当前类的路径
//			int end = path.indexOf("WEB-INF");
//			String path2 = path.substring(1,end-1);
//			projectPath = File.separator + path2 + projectPath;
//	//		System.out.println("------------------------");
//			
//			Locale locale = Locale.getDefault(); 
//			ResourceBundle localResource = ResourceBundle.getBundle("interfaceExchange", locale); 
//			if(!ip.contains("192.168.")){//在城管委以192.168开头的地址不执行
//				//if(ip.equals("172.16.9.63")){//是63的话，则一直交换
//					exchange(projectPath);
////				}else if(ip.equals(localResource.getString("15ip"))){//是15的话，则一直交换
////					exchange(projectPath);
////				}else if(ip.equals(localResource.getString("16ip"))){//是16的话，则要判断15是否是启动的
////					boolean flag = WfUtilsEX.ifActivities(localResource.getString("15ip"),localResource.getString("1516port"));//判断15是否是启动的
////					System.out.println("--flag--"+flag); 
////					if(!flag){//15没启动，则启动16的交换
////						exchange(projectPath);
////					}
////				}			
//			}	
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
	}
	
	/**
	 * 交换
	 * @param projectPath
	 */
	public void exchange(String projectPath){
		try{
			callWebService.syncUserAndOrgWebService();
		}catch (Exception e) {						
			logger.error("(接口)同步用户或者行政组织到方欣的接口异常 "+SysTraceLogWriter.MESSAGE_SEPARATOR + e.getMessage(), e);
		}		
		try{
			ywWebserviceForWbService.exchangeYwWebserviceForWb();
		}catch (Exception e) {						
			System.out.println("-网办交换异常-");
			logger.error("网办交换异常"+SysTraceLogWriter.MESSAGE_SEPARATOR + e.getMessage(), e);			
		}
		try{
			ssgdServiceImpl.readXml(projectPath);
		}catch (Exception e) {						
			System.out.println("-设施改动解析异常-");
			logger.error("设施改动解析异常"+SysTraceLogWriter.MESSAGE_SEPARATOR + e.getMessage(), e);			
		}
		try{			
			hwggService.readXml(projectPath);
		}catch (Exception e) {						
			System.out.println("-户外广告解析异常-");
			logger.error("户外广告解析异常"+SysTraceLogWriter.MESSAGE_SEPARATOR + e.getMessage(), e);	
		}
		try{
			qyzzService.readXml(projectPath);
		}catch (Exception e) {						
			System.out.println("-企业资质解析异常-");
			logger.error("企业资质解析异常"+SysTraceLogWriter.MESSAGE_SEPARATOR + e.getMessage(), e);
		}
		try{
			rqqyjyxkGdService.readXml(projectPath);
		}catch (Exception e) {						
			System.out.println("-经营许可--管道--解析异常-");
			logger.error("管道解析异常"+SysTraceLogWriter.MESSAGE_SEPARATOR + e.getMessage(), e);
		}
		try{
			rqqyjyxkPzService.readXml(projectPath);
		}catch (Exception e) {						
			System.out.println("-经营许可--瓶装--解析异常-");
			logger.error("瓶装解析异常"+SysTraceLogWriter.MESSAGE_SEPARATOR + e.getMessage(), e);
		}
		
		try {
			dlzyService.readXml(projectPath);
		} catch (Exception e) {
			System.out.println("-道路占用--解析异常-");
			logger.error("道路占用解析异常"+SysTraceLogWriter.MESSAGE_SEPARATOR + e.getMessage(), e);
		}
		
		try {
			csdlwjService.readXml(projectPath);
		} catch (Exception e) {
			System.out.println("-道路挖掘--解析异常-");
			logger.error("道路挖掘解析异常"+SysTraceLogWriter.MESSAGE_SEPARATOR + e.getMessage(), e);
		}
		
		try {
			hwCsshljCzService.readXml(projectPath);
		} catch (Exception e) {
			System.out.println("-处置--解析异常-");
			logger.error("处置解析异常"+SysTraceLogWriter.MESSAGE_SEPARATOR + e.getMessage(), e);
		}
		
		try {
			hwShljqsService.readXml(projectPath);
		} catch (Exception e) {
			System.out.println("-陆域--解析异常-");
			logger.error("陆域解析异常"+SysTraceLogWriter.MESSAGE_SEPARATOR + e.getMessage(), e);
		}
		
		try {
			hwShljYsService.readXml(projectPath);
		} catch (Exception e) {
			System.out.println("-水域--解析异常-");
			logger.error("水域解析异常"+SysTraceLogWriter.MESSAGE_SEPARATOR + e.getMessage(), e);
		}
		
		try {
			ggcsService.readXml(projectPath);
		} catch (Exception e) {
			System.out.println("-公厕--解析异常-");
			logger.error("公厕解析异常"+SysTraceLogWriter.MESSAGE_SEPARATOR + e.getMessage(), e);
		}
		
		try {
			pfXzService.readXml(projectPath);
		} catch (Exception e) {
			System.out.println("-排放--解析异常-");
			logger.error("排放解析异常"+SysTraceLogWriter.MESSAGE_SEPARATOR + e.getMessage(), e);
		}
		
		try {
			xnXzService.readXml(projectPath);
		} catch (Exception e) {
			System.out.println("-消纳--解析异常-");
			logger.error("消纳解析异常"+SysTraceLogWriter.MESSAGE_SEPARATOR + e.getMessage(), e);
		}
		
		try {
			czzXzfzService.readXml(projectPath);
		} catch (Exception e) {
			System.out.println("-处置证-新增发证--解析异常-");
			logger.error("处置证-新增发证解析异常"+SysTraceLogWriter.MESSAGE_SEPARATOR + e.getMessage(), e);
		}
		
		try {
			czzNsxzService.readXml(projectPath);
		} catch (Exception e) {
			System.out.println("-处置证-年审续证--解析异常-");
			logger.error("处置证-年审续证解析异常"+SysTraceLogWriter.MESSAGE_SEPARATOR + e.getMessage(), e);
		}
		
		try {
			czzBghzService.readXml(projectPath);
		} catch (Exception e) {
			System.out.println("-处置证-变更换证--解析异常-");
			logger.error("处置证-变更换证解析异常"+SysTraceLogWriter.MESSAGE_SEPARATOR + e.getMessage(), e);
		}
		
		try {
			czzYsbbService.readXml(projectPath);
		} catch (Exception e) {
			System.out.println("-处置证-遗失补办--解析异常-");
			logger.error("处置证-遗失补办解析异常"+SysTraceLogWriter.MESSAGE_SEPARATOR + e.getMessage(), e);
		}
		
		try {
			czzShhzService.readXml(projectPath);
		} catch (Exception e) {
			System.out.println("-处置证-损坏换证--解析异常-");
			logger.error("处置证-损坏换证解析异常"+SysTraceLogWriter.MESSAGE_SEPARATOR + e.getMessage(), e);
		}
		
		try{
			callWebService.callWebService2();
		}catch (Exception e) {						
			System.out.println("-状态交换异常-");
			logger.error("状态交换异常"+SysTraceLogWriter.MESSAGE_SEPARATOR + e.getMessage(), e);
		}
		
		try{
			callWebService.callStopPublicWebService();
		}catch (Exception e) {						
			System.out.println("-结束案件公示交换异常-");
			logger.error("结束案件公示交换异常"+SysTraceLogWriter.MESSAGE_SEPARATOR + e.getMessage(), e);
		}
		
		try{
			ywZhengwuInfoService.exchangeYwZhengwuInfo();
		}catch (Exception e) {						
			System.out.println("-政务中心交换异常-");
			logger.error("政务中心交换异常"+SysTraceLogWriter.MESSAGE_SEPARATOR + e.getMessage(), e);
		}
		
		try{
			ywClosecaseService.changeAllCaseState();			
		}catch (Exception e) {						
			System.out.println("-更改GIS案件状态-");
			logger.error("更改GIS案件状态异常"+SysTraceLogWriter.MESSAGE_SEPARATOR + e.getMessage(), e);
		}
	}
	
	
	
}